package com.focus.xyz.main.pages;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BasePage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/**
 * Created by chenmeng on 2016/5/24.
 */
public class XyzMainPage extends BasePage {
    private WebDriver driver;
    private Action action;
    private String url = "http://www.xyz.cn/";

    @FindBy(id = "username")
    private WebElement userName;
    @FindBy(id = "input2")
    private WebElement password;
    @FindBy(id = "loginBut")
    private WebElement loginBtn;
    @FindBy(id = "dev_login_for_insure")
    private WebElement loginLink;

    public XyzMainPage(WebDriver driver,Action action){
        super(driver,action);
        this.action = action;
        super.url = url;
        PageFactory.initElements(driver,this);
    }

    public void login(String user,String pass) throws Exception{

        action.waitForPageLoad();
        action.inputText(userName,user);
        action.inputText(password,pass);
        action.click(loginBtn);
        action.waitForPageLoad();
    }

    public void clickLoginLink() throws Exception{
        action.click(loginLink);
    }

    public boolean isLogined() throws Exception{
        boolean flag ;
        if(action.isElementExsit(By.xpath("//*[@id=\"dev_login_for_insure\"]"))){
            flag = false;
        }else{
            flag = true;
        }
        return flag;
    }


}
